package com.ruoyi.web.controller.ted;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.demooo1.domain.TedAdvise;
import com.ruoyi.demooo1.service.ITedAdviseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 建议Controller
 *
 * @author ruoyi
 * @date 2023-08-19
 */
@RestController
@RequestMapping("/ted/advise")
public class TedAdviseController extends BaseController
{
    @Autowired
    private ITedAdviseService tedAdviseService;

    /**
     * 查询建议列表
     */
//    @PreAuthorize("@ss.hasPermi('tedAdvise:advise:list')")
    @GetMapping("/list")
    public TableDataInfo list(TedAdvise tedAdvise)
    {
        startPage();
        List<TedAdvise> list = tedAdviseService.selectTedAdviseList(tedAdvise);
        return getDataTable(list);
    }

    /**
     * 导出建议列表
     */
//    @PreAuthorize("@ss.hasPermi('tedAdvise:advise:export')")
    @Log(title = "建议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TedAdvise tedAdvise)
    {
        List<TedAdvise> list = tedAdviseService.selectTedAdviseList(tedAdvise);
        ExcelUtil<TedAdvise> util = new ExcelUtil<TedAdvise>(TedAdvise.class);
        util.exportExcel(response, list, "建议数据");
    }

    /**
     * 获取建议详细信息
     */
//    @PreAuthorize("@ss.hasPermi('tedAdvise:advise:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tedAdviseService.selectTedAdviseByID(id));
    }

    /**
     * 新增建议
     */
//    @PreAuthorize("@ss.hasPermi('tedAdvise:advise:add')")
    @Log(title = "建议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TedAdvise tedAdvise)
    {
        return toAjax(tedAdviseService.insertTedAdvise(tedAdvise));
    }

    /**
     * 修改建议
     */
//    @PreAuthorize("@ss.hasPermi('tedAdvise:advise:edit')")
    @Log(title = "建议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TedAdvise tedAdvise)
    {
        return toAjax(tedAdviseService.updateTedAdvise(tedAdvise));
    }

    /**
     * 删除建议
     */
//    @PreAuthorize("@ss.hasPermi('tedAdvise:advise:remove')")
    @Log(title = "建议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tedAdviseService.deleteTedAdviseByIDs(ids));
    }
}
